package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduSchool.*;
import com.jwsoft.manager.core.integration.EduSchoolIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 所属学校表网关
 *
 * @author wangtao
 * @since 2022-11-25
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "所属学校表", description = "所属学校表")
public class EduSchoolController {

    @Autowired
    public EduSchoolIntegration eduSchoolIntegration;

    @Operation(summary = "所属学校表分页查询",description = "所属学校表分页查询")
    @PostMapping(value = "/eduschool0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSchoolVO>> getList(@RequestBody @Validated EduSchoolQueryVO vo) {
        return AppResponse.successData(eduSchoolIntegration.getList(vo));
    }

    @Operation(summary = "所属学校表根据主键查询详情-校验招生计划", description = "所属学校表根据主键查询详情-校验招生计划")
    @PostMapping(value = "/eduschool0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVO> getById(@RequestBody @Validated EduSchoolKeyVO vo) {
        return AppResponse.successData(eduSchoolIntegration.getById(vo));
    }

    @Operation(summary = "所属学校表根据主键查询详情-不校验招生计划", description = "所属学校表根据主键查询详情-不校验招生计划")
    @PostMapping(value = "/eduschool0012", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVO> getDetail(@RequestBody @Validated EduSchoolKeyVO vo) {
        return AppResponse.successData(eduSchoolIntegration.getDetail(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "所属学校表新增",description = "所属学校表新增")
    @PostMapping(value = "/eduschool0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduSchoolVO vo) {
        return AppResponse.successData(eduSchoolIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "所属学校表修改",description = "所属学校表修改")
    @PostMapping(value = "/eduschool0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSchoolVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduSchoolVO vo) {
        return AppResponse.successData(eduSchoolIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "所属学校表删除",description = "所属学校表删除")
    @PostMapping(value = "/eduschool0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduSchoolKeyVO vo) {
        eduSchoolIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @PostMapping(value = "/eduschool0007", produces = "application/json;charset=UTF-8")
    @Operation(summary = "获取学校预报名统计信息", description = "获取学校预报名统计信息")
    public AppResponse<PageInfo<EduSchoolVO>> getSchoolStaData(
            @RequestBody @Validated EduSchoolQueryVO vo) {

        return AppResponse.successData(eduSchoolIntegration.getSchoolStaData(vo));
    }

    @PostMapping(value = "/eduschool0008", produces = "application/json;charset=UTF-8")
    @Operation(summary = "根据行政区划获取学校地图上的信息", description = "根据行政区划获取学校地图上的信息")
    public AppResponse<List<EduSchoolMapVO>> getSchoolStaData(
            @RequestBody @Validated EduSchoolMapQueryVO vo) {
        return AppResponse.successData(eduSchoolIntegration.getSchoolMapList(vo));
    }

    @RequestMapping(
            value = "/eduschool0009",
            method = {RequestMethod.POST, RequestMethod.GET})
    @Operation(summary = "学校信息导出", description = "学校信息导出")
    @NoSignCrypto
    public void downloadData(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            @RequestBody(required = false) EduSchoolQueryVO vo,
            HttpServletResponse response) {

        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        eduSchoolIntegration.downloadData(vo,response);

    }

    @PostMapping(value = "/eduschool0010", produces = "application/json;charset=UTF-8")
    @Operation(summary = "手机端幼儿园报名学校查询", description = "手机端幼儿园报名学校查询")
    public AppResponse<PageInfo<EduSchoolVO> > getAppNurserySchoolList(
            @RequestBody @Validated EduSchoolQueryVO vo) {
        return AppResponse.successData(eduSchoolIntegration.getAppNurserySchoolList(vo));
    }
    @PostMapping(value = "/eduschool0011", produces = "application/json;charset=UTF-8")
    @Operation(summary = "手机端义务段报名学校查询", description = "手机端义务段报名学校查询")
    public AppResponse<PageInfo<EduSchoolVO> > getAppEnrollSchoolList(
            @RequestBody @Validated EduSchoolQueryVO vo) {
        return AppResponse.successData(eduSchoolIntegration.getAppEnrollSchoolList(vo));
    }
    @PostMapping(value = "/eduschool0013", produces = "application/json;charset=UTF-8")
    @Operation(summary = "根据用户分配的组织判断是否管理员", description = "手机端义务段报名学校查询")
    public AppResponse<Boolean> managerCheck(
            @RequestBody EduSchoolKeyVO vo) {
        return AppResponse.successData(eduSchoolIntegration.managerCheck(vo));
    }

}
